package org.dei.perla.rockfall.gui.queryforge.panels;

import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import org.dei.perla.rockfall.gui.queryforge.ReadableStatusPanel;

public class RunningStatus4Panel extends ReadableStatusPanel {

	private JComboBox jComboBox1;
	private JCheckBox jCheckBox2;
	private JCheckBox jCheckBox3;
	private JCheckBox jCheckBox4;

	public RunningStatus4Panel(String title) {
		super(title);
		// TODO Auto-generated constructor stub
	}

	@Override
	public int getStatus() {
		int retvalue = 0;
		int index = this.jComboBox1.getSelectedIndex();
		
		if(index == 1)
			retvalue |= 0x0800;
				
		boolean check2 = this.jCheckBox2.isSelected();
		boolean check3 = this.jCheckBox3.isSelected();
		boolean check4 = this.jCheckBox4.isSelected();
		
		
		if(check2){
			retvalue |= 0x1000;
		}
		
		if(check3){
			retvalue |= 0x0400;
		}
		
		if(check4){
			retvalue |= 0x0080;
		}
		
		
		return retvalue;
	}

	@Override
	public void setStatus(int stato) {
		// TODO Auto-generated method stub
		this.jComboBox1.setSelectedIndex((stato&0x0800)/0x0800);
		this.jCheckBox2.setSelected((stato&0x1000)>0);
		this.jCheckBox3.setSelected((stato&0x400)>0);
		this.jCheckBox4.setSelected((stato&0x80)>0);
	}

	@Override
	protected void setupInternalComponents() {
		
		//Primo blocco di scelte
		
		jComboBox1 = new JComboBox();
		jComboBox1.setEditable(false);
		jComboBox1.addItem("mems");
		jComboBox1.addItem("geofono");
		JLabel jlabel1 = new JLabel("Imposta acquisizione o su mems o su geofono");
		JPanel jpanel1 = new JPanel();
		BoxLayout layout1 = new BoxLayout(jpanel1, BoxLayout.X_AXIS);
		jpanel1.add(jlabel1);
		jpanel1.add(jComboBox1);
		
		//Secondo Blocco di scelte
		
		jCheckBox2 = new JCheckBox();
		jCheckBox2.setSelected(true);
		JLabel jlabel2 = new JLabel("Abilita LED scheda");
		JPanel jpanel2 = new JPanel();
		BoxLayout layout2 = new BoxLayout(jpanel2, BoxLayout.X_AXIS);
		jpanel2.add(jlabel2);
		jpanel2.add(jCheckBox2);
		
        //Terzo Blocco di scelte
		
		jCheckBox3 = new JCheckBox();
		jCheckBox3.setSelected(true);
		JLabel jlabel3 = new JLabel("Abilita alimentazione uscita CRK");
		JPanel jpanel3 = new JPanel();
		BoxLayout layout3 = new BoxLayout(jpanel3, BoxLayout.X_AXIS);
		jpanel3.add(jlabel3);
		jpanel3.add(jCheckBox3);
		
		//Quarto blocco di scelte
		
		jCheckBox4 = new JCheckBox();
		jCheckBox4.setSelected(true);
		JLabel jlabel4 = new JLabel("alimentazione analogica");
		JPanel jpanel4 = new JPanel();
		BoxLayout layout4 = new BoxLayout(jpanel4, BoxLayout.X_AXIS);
		jpanel4.add(jlabel4);
		jpanel4.add(jCheckBox4);
			
		//aggiungo tutti i blocchi
		this.add(jpanel1);
		this.add(jpanel2);
		this.add(jpanel3);
		this.add(jpanel4);
	}

}
